#ifndef     __FLASH_H
#define     __FLASH_H

#include <stdint.h>

namespace driver::flash {

struct Sector {
    uint32_t Addr;
    uint32_t Size;
};

// BootLoader
constexpr uint32_t Sector0Addr = 0x08000000;
constexpr uint32_t Sector0Size = 16 * 1024;

constexpr uint32_t Sector1Addr = Sector0Addr + Sector0Size;
constexpr uint32_t Sector1Size = 16 * 1024;

constexpr uint32_t Sector2Addr = Sector1Addr + Sector1Size;
constexpr uint32_t Sector2Size = 16 * 1024;

constexpr uint32_t Sector3Addr = Sector2Addr + Sector2Size;
constexpr uint32_t Sector3Size = 16 * 1024;

constexpr uint32_t Sector4Addr = Sector3Addr + Sector3Size;
constexpr uint32_t Sector4Size = 64 * 1024;

constexpr uint32_t Sector5Addr = Sector4Addr + Sector4Size;
constexpr uint32_t Sector5Size = 128 * 1024;

constexpr uint32_t Sector6Addr = Sector5Addr + Sector5Size;
constexpr uint32_t Sector6Size = 128 * 1024;

constexpr uint32_t Sector7Addr = Sector6Addr + Sector6Size;
constexpr uint32_t Sector7Size = 128 * 1024;


bool erase(uint32_t addr, uint32_t size);
bool write(uint32_t addr, const void *data, uint32_t size);
void read(uint32_t addr, void *data, uint32_t size);

constexpr uint32_t BootAddr = Sector0Addr;
constexpr uint32_t BootSize = Sector0Size; // 16kb

constexpr uint32_t DataAddr = Sector1Addr; 
constexpr uint32_t DataSize = Sector1Size; // 16kb

constexpr uint32_t OtaInfoAddr = Sector2Addr;
constexpr uint32_t OtaInfoSize = Sector2Size; // 16kb

// 16 + 16 + 16 + 16 + 64 + 128 * 7

constexpr uint32_t AppAddr = Sector5Addr;
constexpr uint32_t AppSize = Sector5Size + Sector6Size;

constexpr uint32_t OtaAddr = Sector7Addr;
constexpr uint32_t OtaSize = AppSize;


}


#endif
